<template>
	<view class="section">
		<view @click="safeBack">
			dack
		</view>
		<view class="list"> 
				<view class="row" v-for="item in scoredPicurlList" :key="item.id">
					<view class="left">
						<uni-icons type="download-filled" size="20" color="#28b389"></uni-icons>
						<image :src="item.smallPicurl" mode="aspectFill" style="height: 100rpx;width: 100rpx;"></image>
					</view>
					<view class="right">
						<view class="text">
							{{item.score}}
						</view>
					</view>
				</view>
		</view>
	</view>
</template>

<script setup>
	import {ref} from "vue";
	import { onLoad } from '@dcloudio/uni-app'; // ✅ 正确来源
	import{ apiGetUserInfo_ctt} from "@/api/api_ctt.js"
	const scoredPicurlList = ref([])
	const userInfo = ref([])
	
	function safeBack() {
	 
	    uni.switchTab({ url: '/pages/user/user' }); // 或者换成你的首页路径
	  
	}
	 
	const getUserInfo = async () => {
	  const res = await apiGetUserInfo_ctt();
	  const rawList = res.data[0].scoreSize || [];
	
	  // 使用 Set 去重
	  const uniqueList = [];
	  const seen = new Set();
	
	  for (const item of rawList) {
	    const key = `${item.classid}_${item.id}_${item.score}`;
	    if (!seen.has(key)) {
	      seen.add(key);
	      uniqueList.push(item);
	    }
	  }
	
	  console.log("去重后的列表:", uniqueList);
	
	  // 清空旧列表
	  scoredPicurlList.value = [];
	
	  // 逐条请求
	  for (const item of uniqueList) {
	    await fetchWallItem(item.classid, item.id, item.score);
	  }
	};

	const fetchWallItem = async (classid, id) => {
	  try {
	    const res = await uni.request({
	      url: 'https://xrqr0h0x1w.gzg.sealos.run/get_scoredListInfo', // 替换成你的真实地址
	      method: 'POST',
	      data: { classid, id },
	      header: { 'Content-Type': 'application/json' }
	    })
	
	    if (res.data.code === 200 && res.data.data) {
	      const { _id, smallPicurl, score } = res.data.data
	      scoredPicurlList.value.push({ 
	        id: _id, 
			score,
	        smallPicurl, 
	        debugClassid: classid,
	        debugId: id 
	      })

		  console.log("获成功" ,scoredPicurlList.value)
	    } else {
	      console.warn('获取失败:', res.data.message)
	    }
	  } catch (err) {
	    console.error('单个请求失败:', err)
	  }
	}
	 getUserInfo()
</script>

<style scoped lang="scss">
	.list .row {
	  display: flex;
	  align-items: center;
	  position: relative;
	  justify-content: space-between;
	  padding: 0 30rpx;
	  height: 160rpx;
	  border: 1px solid #eee;
	  background: #fff;
	}
	
	/* 最后一项不显示底边框 */
	.list .row:last-child {
	  border-bottom: 0;
	}
	
	/* 左侧区域 */
	.list .row .left {
	  display: flex;
	  align-items: center;
	}
	
	/* 左侧文字 */
	.list .row .left .text {
	  padding-left: 20rpx;
	  color: #666;
	}
	
	/* 右侧区域 */
	.list .row .right {
	  display: flex;
	  align-items: center;
	}
	
	/* 右侧文字 */
	.list .row .right .text {
	  font-size: 28rpx;
	  color: #333;
	}
	
	/* 隐藏按钮（用于滑动操作等） */
	.list .row button {
	  position: absolute;
	  top: 0;
	  left: 0;
	  height: 100rpx;
	  width: 100%;
	  opacity: 0;
	}

	
</style>
